import request from '@/utils/request'
import { type Result } from '@/types/result'
import { type PublishProductForm } from '@/types/product'

// 分页获取商品信息列表(可以根据商品类型)
export function getProductListApi(
  currentPage: number,
  pageSize: number,
  typeId: string,
): Promise<Result> {
  return request.get('/productInfo/list', { params: { currentPage, pageSize, typeId } })
}
// 根据搜索条件查询商品信息
export function searchProductListApi(
  currentPage: number,
  pageSize: number,
  condition: string,
): Promise<Result> {
  return request.get('/productInfo/essearch', { params: { currentPage, pageSize, condition } })
}

// 根据地点查询商品信息
export function getNearbyProductListApi(
  currentPage: number,
  pageSize: number,
  adCode: string,
): Promise<Result> {
  return request.get('/productInfo/position', { params: { currentPage, pageSize, adCode } })
}

// 根据 ID 查询商品信息
export function getProductByIdApi(id: string): Promise<Result> {
  return request.get('/productInfo/id', { params: { id } })
}

// 新增商品信息
export function addProductInfoApi(productInfo: PublishProductForm): Promise<Result> {
  return request.post('/productInfo/add', productInfo)
}

// 删除商品信息
export function deleteProductInfoApi(id: string): Promise<Result> {
  return request.delete(`/productInfo/delete`, { params: { id } })
}

// 更新商品信息
export function updateProductInfoApi(PublishProductForm: PublishProductForm): Promise<Result> {
  return request.put('/productInfo/update', PublishProductForm)
}

// 获取商品分类
export function getAllProductTypesApi(): Promise<Result> {
  return request.get('/productInfo/types')
}

// 根据用户ID获取“已发布”商品信息
export function getMinePublishedProductListApi(
  currentPage: number,
  pageSize: number,
): Promise<Result> {
  return request.get('/productInfo/published', { params: { currentPage, pageSize } })
}

// 根据用户ID获取“已卖出”商品信息
export function getMineSoldProductListApi(currentPage: number, pageSize: number): Promise<Result> {
  return request.get('/productInfo/sold', { params: { currentPage, pageSize } })
}

// 根据用户ID获取“已买到”商品信息
export function getMinePurchasedProductListApi(
  currentPage: number,
  pageSize: number,
): Promise<Result> {
  return request.get('/productInfo/purchased', { params: { currentPage, pageSize } })
}

// 根据用户ID获取“已收藏”商品信息
export function getMineCollectedProductListApi(
  currentPage: number,
  pageSize: number,
): Promise<Result> {
  return request.get('/productInfo/collected', { params: { currentPage, pageSize } })
}
